package com.datang.pet.api.commentController;/*
 * @auther 顶风少年
 * @mail dfsn19970313@foxmail.com
 * @date 2019-06-15 19:07
 * @notify
 * @version 1.0
 */

import com.datang.pet.common.response.Result;
import com.datang.pet.common.utils.MD5;
import com.datang.pet.common.utils.StringUtils;
import com.datang.pet.service.CommentService;
import com.datang.pet.vo.AddTwoCommentRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class AddTwoCommentController {
    @Autowired
    private CommentService commentService;

    @PostMapping("/addTwoComment")
    public Result addTwoComment(@RequestBody AddTwoCommentRequest addTwoCommentRequest)throws Exception{

        if (!StringUtils.isNUll(addTwoCommentRequest.getOneCommentId())) {
            throw new Exception("一级评论id为空");
        }
        if (!StringUtils.isNUll(addTwoCommentRequest.getOneCommentUserId())) {
            throw new Exception("一级评论作者id为空");
        }
        if (!StringUtils.isNUll(addTwoCommentRequest.getTalkUserId())) {
            throw new Exception("原文作者id为空");
        }
        if (!StringUtils.isNUll(addTwoCommentRequest.getTalkId())) {
            throw new Exception("talkId为空");
        }
        if (!StringUtils.isNUll(addTwoCommentRequest.getTwoCommentUserId())) {
            throw new Exception("评论人id为空");
        }
        if (!StringUtils.isNUll(addTwoCommentRequest.getCommentContent())) {
            throw new Exception("评论内容为空");
        }
        try {
            addTwoCommentRequest.setTwoCommentUserId(MD5.decryptData(addTwoCommentRequest.getTwoCommentUserId()));
        } catch (Exception e) {
            throw new Exception("userId解密出错！");
        }


        commentService.addTwoComment(addTwoCommentRequest);
        return Result.ok("成功");
    }
}
